import json

from django.core import serializers
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt

from app.Matrix import Matrix


@csrf_exempt
def multiplication(request):
    json_data = json.loads(request.body)

    matrix1 = Matrix()
    matrix2 = Matrix()

    matrix1.initWithMatrix(json_data['first'])
    matrix2.initWithMatrix(json_data['second'])

    result = Matrix.multiply(matrix1, matrix2)

    return JsonResponse(result.data, safe=False)
